package com.base.cn.platform.os.controller.agent.settlement;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.service.course.agent.settlement.AgentSettlementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 推广员结算记录Controller
 *
 * @author LIZHIPENG
 * @create 2018-05-14 下午 6:16
 */
@Controller
@RequestMapping("/admin/agent/settlement")
public class AdminAgentSettlementController extends AdminBaseController {

    @Autowired
    private AgentSettlementService agentSettlementService;

    /**
     * 初始化推广员结算列表
     * @return
     */
    @RequestMapping("/queryAgentSettlementList")
    public String queryAgentSettlementList(){
        return resultPage("/agent/settlement/agent-settlement-list");
    }

    /**
     * 查询结算数据
     * @param model
     * @param currentPage 页码
     * @param params 条件
     * @return
     */
    @RequestMapping("/ajaxQueryAgentSettlementList")
    public String ajaxQueryAgentSettlementList(Model model,
                                               @RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
                                               @RequestBody Map<String, Object> params){
        Map<String, Object> dataMap = agentSettlementService.querySettlementListPage(currentPage, params, true);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/agent/settlement/ajax-agent-settlement-list");
    }

    /**
     * 初始化结算明细页面
     * @param model
     * @param agentSettlementId 结算ID
     * @return
     */
    @RequestMapping("/agentSettlementInfo")
    public String agentSettlementInfo(Model model,
                                      @RequestParam("agentSettlementId")BigDecimal agentSettlementId){
        Map<String, Object> agentSettlement = agentSettlementService.findSettlementById(agentSettlementId, true);
        model.addAttribute("agentSettlement", agentSettlement);
        return resultPage("/agent/settlement/agent-settlement-info");
    }

    /**
     * 去往确认结算页面
     * @param model
     * @param agentSettlementId 结算ID
     * @return
     */
    @RequestMapping("/toConfirmView")
    public String toConfirmView(Model model,
                                @RequestParam("agentSettlementId") BigDecimal agentSettlementId){
        model.addAttribute("agentSettlementId", agentSettlementId);
        return resultPage("/agent/settlement/agent-settlement-confirm");
    }

}
